package ui.control
{
    import flash.display.MovieClip;
    import flash.geom.Rectangle;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;

    /** Centered in rectangle area TextField **/
    public class Caption extends MovieClip
    {
        private var _text: TextField = new TextField
        private var _rect: Rectangle
        
        public function Caption(rect:Rectangle)
        {
            super();
            this.rect = rect;
            
            _text.autoSize = TextFieldAutoSize.CENTER;
            _text.height = 20;
            _text.border = true;
            _text.borderColor = 0xFF0000;
            _text.background = true;
            _text.backgroundColor = 0xFFFFFF;
            _text.defaultTextFormat = new TextFormat("_sans", 12, 0x000000);
            addChild(_text);
            draw();
        }
      
        private function draw (): void
        {
            _text.x = _rect.x + (_rect.width - _text.width)/2
            _text.y = _rect.y + (_rect.height - _text.height)/2
        }
      
        public function set text (value:String): void
        {
            _text.text = value
            draw()
        }
      
        public function get text (): String
        {
            return _text.text
        }
      
        public function set rect (value:Rectangle): void
        {
            _rect = value
            draw()
        } 
      
        public function get rect (): Rectangle
        {
            return _rect
        }
    }
}